﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;

namespace ui
{
    public class _button : _control
    {
        string _text = "Button";
        Color _PressedColor = Color.Green;
        Color _NotPressedColor = Color.Red;
        Color _BorderColor = Color.Black;
        Color _BackgroundColor = Color.White;
        Color _ForeColor = Color.Black;
        int _Padding = 1;
        bool _StateButton = false;

        public _button()
            : base()
        {
            type = ControlTypes.Button;
        }

        public override void setup(PictureBox p)
        {
            base.setup(p);
        }

        [Category("Data"), Description("Text")]
        public string text
        {
            get { return _text; }
            set { _text = value; if (pic != null) pic.Invalidate(); }
        }

        [Category("Appearance"), Description("Padding")]
        public int Padding
        {
            get { return _Padding; }
            set { _Padding = value; if (pic != null) pic.Invalidate(); }
        }

        [Category("Appearance"), Description("Is State Button")]
        public bool StateButton
        {
            get { return _StateButton; }
            set { _StateButton = value; }
        }

        [XmlElement(Type = typeof(_xmlcolor))]
        [Category("Appearance"), Description("Pressed Color")]
        public Color PressedColor
        {
            get { return _PressedColor; }
            set { _PressedColor = value; if (pic != null) pic.Invalidate(); }
        }

        [XmlElement(Type = typeof(_xmlcolor))]
        [Category("Appearance"), Description("Not Pressed Color")]
        public Color NotPressedColor
        {
            get { return _NotPressedColor; }
            set { _NotPressedColor = value; if (pic != null) pic.Invalidate(); }
        }

        [XmlElement(Type = typeof(_xmlcolor))]
        [Category("Appearance"), Description("Border Color")]
        public Color BorderColor
        {
            get { return _BorderColor; }
            set { _BorderColor = value; if (pic != null)pic.Invalidate(); }
        }

        [XmlElement(Type = typeof(_xmlcolor))]
        [Category("Appearance"), Description("Background Color")]
        public Color BackgroundColor
        {
            get { return _BackgroundColor; }
            set { _BackgroundColor = value; if (pic != null) pic.Invalidate(); }
        }

        [XmlElement(Type = typeof(_xmlcolor))]
        [Category("Appearance"), Description("Fore Color")]
        public Color ForeColor
        {
            get { return _ForeColor; }
            set { _ForeColor = value; if (pic != null) pic.Invalidate(); }
        }

        public override void render(object sender, PaintEventArgs e)
        {
            g = e.Graphics;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;

            SizeF s = g.MeasureString(text, parent.mainFont);
            Brush fill = new SolidBrush(NotPressedColor);

            g.Clear(BackgroundColor);
            g.FillRectangle(fill, new Rectangle(Padding, Padding, width - ((Padding * 2) + 1), height - ((Padding * 2) + 1)));
            g.DrawRectangle(new Pen(BorderColor), new Rectangle(Padding, Padding, width - ((Padding * 2) + 1), height - ((Padding * 2) + 1)));
            g.DrawString(text, parent.mainFont, new SolidBrush(ForeColor), pic.Width / 2 - s.Width / 2, pic.Height / 2 - s.Height / 2);

            base.render(sender, e);
        }
    }
}
